﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using RoccaStore.Enums;
using RoccaStore.Utils;
using RoccaStore.Extensions;

namespace RoccaStore
{
    [Table("FileInfo")]
    public class FileInfo
    {
        #region Properties

        [Key]
        [Column("FileInfoID")]
        public int ID { get; set; }

        public int? AccountID { get; set; }

        [ForeignKey("AccountID")]
        public virtual Account Account { get; set; }

        public string Filename { get; set; }

        public FileType Type { get; set; }

        public string Extension { get; set; }

        public string IP { get; set; }

        public DateTime CreatedDate { get; set; }        

        /// <summary>
        /// Size in bytes
        /// </summary>
        public long Size { get; set; }

        [NotMapped]
        public string FormattedSize { get { return this.Size.FormatBytes(); } }

        #endregion

        #region Constructors

        public FileInfo()
        {
            this.CreatedDate = DateTime.Now;
        }

        #endregion

        public void UpdateFileType()
        {
            switch (this.Extension)
            {
                case ".png":
                case ".jpg":
                case ".jpeg":
                case ".bmp":
                case ".gif":

                    this.Type = FileType.Image;
                    break;
                default:
                    this.Type = FileType.File;
                    break;
            }
        }
    }
}
